/**
  * File  : Thread.h
  * Time  : 2014-12-12 21:23
  * Author: KashingLee 
  * Ref   :  mooon
  */
#ifndef PLCC_THREAD_THREAD_H_
#define PLCC_THREAD_THREAD_H_
#include <stdint.h>
#include <pthread.h>
#include "ThreadException.h"

class Thread {
 friend void *ThreadFunc(void *arg_this);

 public:
  Thread();
  virtual ~Thread();

  uint32_t thread_id() const { return static_cast<uint32_t>(id_); }
  void Start(bool be_detached = false);
  void Join();
  void Detach();
  bool IsJoinable();
 
 public:
  static uint32_t CurrentThreadId();
 
 private:
  virtual void Run() = 0;
  virtual bool BeforeRun() { return true; }
  virtual void AfterRun()  { }

 private:
  pthread_t      id_;
  pthread_attr_t attr_;
	
};
#endif //PLCC_THREAD_THREAD_H_
